<?php

use console\db\channels\TransferTableMigration;
use yii\db\Query;

/**
 * 文章统计信息转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300010_000011_t_cms_article_stats extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function validateTransfer(&$data) {
        if (!parent::validateTransfer($data)) {
            return false;
        }
        $article = (new Query)->from('{{%cms_article}}')->where([
            'id' => $data['article_id']
        ])->one();
        if (empty($article)) {
            return false;
        }
        return true;
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'cms_article_stats' => 'ts_article_statistic',
            ],
            'columns' => [
                'article_id',
                'views',
                'likes',
                'comments',
                'created_at',
                'updated_at',
            ],
        ];
    }

}
